#-*-coding:utf8;-*-

from backtesting import Backtest, Strategy
from Indicators import zjjr_I #,zjxc,cdsz,dkcw
from  _utinity import get_data
from ylTDX2 import TFILTER

class Strategy_TDX(Strategy):
    def init(self):
        self.zjjr = self.I(zjjr_I, df)
        long_position=(self.zjjr>0)
        short_position=(self.zjjr==0)
        self.bs=TFILTER(long_position,short_position,0) #N=0表示对买入和卖出信号都过滤,返回1,2表示买入或卖出条件成立
        print(self.bs)

    def next(self):
        if self.bs==1:
            self.buy()
        elif self.bs==2:
            self.sell()      

if __name__=='__main__':
    code=799
    N=60
    df=get_data(code,N) 
    bt = Backtest(df, Strategy_TDX, cash=50_000,commission=.0013,exclusive_orders=False)
    stats = bt.run()
    bt.plot()